package cn.usian.controller;

import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class EmpController {
    @Autowired
    private EmpService empService;
    //查询所有
    @RequestMapping("/findAll")
    public String findAll(Model model,String name){
        List<Emp> list=empService.findAll(name);
        model.addAttribute("list",list);
        model.addAttribute("name",name);
        return "Emp";
    }
    //跳转到添加页面
    @RequestMapping("/tiaoAdd")
    public String tiaoAdd(){
        return "add";
    }
    //添加
    @RequestMapping("/add")
    public String add(Emp emp){
        empService.add(emp);
        return "redirect:/findAll";
    }
    //回显
    @RequestMapping("/findByid")
    public String findByid(int id,Model model){
        Emp emp=empService.findByid(id);
        model.addAttribute("emp",emp);
        return "update";
    }
    //修改
    @RequestMapping("/update")
    public String update(Emp emp){
        empService.update(emp);
        return "redirect:/findAll";
    }
    //删除
    @RequestMapping("/delete")
    public String delete(int id){
        empService.delete(id);
        return "redirect:/findAll";
    }
    //条件查询

}
